package com.ls.fw.data.exp;

import java.util.ArrayList;
import java.util.List;

import com.ls.fw.data.bean.KeyValue;
import com.ls.fw.data.utils.DataUtil;

/**
 * 查询条件函数
 * @author ls
 * 2014年11月21日下午2:33:25
 */
public class MethodComparison extends Comparison implements Cloneable{
	
	//参数
	private List<KeyValue> params = new ArrayList<KeyValue>();
	//条件(distinct)
	private String option;

	public MethodComparison(String name, Object... param) {
		super(name,null);
		if(param!=null){
			for (Object object : param) {
				this.addParam(object);
			}
		}
	}
	
	public static MethodComparison newInstance(String name){
		return new MethodComparison(name,  Operator.EQ, null);
	}
	
	
	public MethodComparison addParam(Object value){
		this.params.add(new KeyValue(value));
		return this;
	}

	public MethodComparison addParam(String key,Object value){
		this.params.add(new KeyValue(key, value));
		return this;
	} 
	
	 
	
	
	@Override
	public String toString() {
		if (option != null) {
			return this.name + "(" + option + " " + DataUtil.joiner(params, ",") + ")";
		}
		return this.name + "(" + DataUtil.joiner(params, ",") + ")";
	}

	public List<KeyValue> getParams() {
		return params;
	}

	public void setParams(List<KeyValue> params) {
		this.params = params;
	}

	public String getOption() {
		return option;
	}

	public MethodComparison setOption(String option) {
		this.option = option;
		return this;
	}
	

	public static void main(String[] args) {
		System.out.println(MethodComparison.newInstance("s"));
	}
}
